package com.partners.controller.test;

/**
 * 多线程
 * @author liangyongle
 * @date 2019-02-12
 */
//@RestController
//@RequestMapping("thread")
public class ThreadController extends Thread {

   public void run(){
       System.out.println(getName()+"是一个演员！");
       int count =0;
       boolean keepRunning = true;
       while (keepRunning){
           System.out.println(getName()+"登台演出："+(++count));
           if(count ==100){
               keepRunning = false;
           }
           if(count %10 == 0){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
       }

       System.out.println(getName()+"的演出结束了！");
   }



    public static void main(String[] args) {
        Thread actor = new ThreadController();
        actor.setName("小明");
        actor.start();
        Thread actress = new Thread(new Actress(),"小花");
        actress.start();
    }

/**
 * 新增累
* */
static class Actress implements Runnable{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+"是一个演员！");
            int count =0;
            boolean keepRunning = true;
            while (keepRunning){
                System.out.println(Thread.currentThread().getName()+"登台演出："+(++count));
                if(count ==100){
                    keepRunning = false;
                }
                if(count %10 == 0){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

            System.out.println(Thread.currentThread().getName()+"的演出结束了！");
        }
    }

}
